package com.sumer.psychology.friend.infrastructure.port;

import com.sumer.psychology.common.Assert;
import com.sumer.psychology.common.domain.model.Author;
import com.sumer.psychology.friend.domain.model.Member;
import com.sumer.psychology.friend.domain.model.MemberId;
import com.sumer.psychology.friend.domain.model.MemberRepository;

/**
 * Member翻译器
 * <p/>
 * User: zhenguang.zhu
 * Date: 2014/9/12
 * Time: 10:26
 */
public class MemberTranslator {
    MemberRepository memberRepository;

    public MemberTranslator(MemberRepository memberRepository) {
        this.memberRepository = memberRepository;
    }

    /**
     * 普通id转成Member
     *
     * @param identity id
     * @return member
     */
    public Member toMember(String identity) {
        Assert.notEmpty(identity);

        return memberRepository().memberOfId(
                new MemberId(identity));
    }

    /**
     * 从Author转Member
     *
     * @param author author
     * @return member
     */
    public Member toMember(Author author) {
        Assert.notNull(author);
        Assert.notEmpty(author.identity());

        return toMember(author.identity());
    }

    private MemberRepository memberRepository() {
        return memberRepository;
    }
}
